﻿// ***********************************************************************
// Assembly         : MVC4Portal
// Author           : LJO+01 (Laurent Jordi)
// Created          : 06-05-2013
//
// Last Modified By : LJO+01 (Laurent Jordi)
// Last Modified On : 06-05-2013
// ***********************************************************************
// <copyright file="_LayoutViewControllers_Base.cs" company="Copyright © Innovacall 2011">
//     Copyright (c) Copyright © Innovacall 2011. All rights reserved.
// </copyright>
// <summary></summary>
// ***********************************************************************

using System;
using System.Linq;
using System.Globalization;
using System.Web.Security;
using InnovaApp.Layers.DomainLayer;
using INNOVACALL.Framework.Common;
using InnovaApp.Portals.MVC4Portal.Models.MetaModels.ContactManagement;
using System.Collections.Generic;
using InnovaApp.Layers.DataLayer;
using EmitMapper;
namespace InnovaApp.Portals.MVC4Portal.Controllers.ViewControllers.LayoutViewControllers
{
    /// <summary>
    /// Class _LayoutViewControllers_Base
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public abstract class _LayoutViewControllers_Base<T> : InnovaApp.Layers.CommonLayer.Controllers.ViewControllers.LayoutViewControllers._LayoutViewControllers_Base<T> where T : InnovaApp.Layers.CommonLayer.Models.ViewModels.LayoutViewModels._LayoutViewModels_Base
    {
        private ManagedContact_MetaModel _currentContact;

        public ManagedContact_MetaModel CurrentContact
        {
            get
            {
                if (_currentContact == null)
                {
                    if (this.CurrentUser != null)
                    {
                        using (DataRepositories _dataContext = new DataRepositories())
                        {
                            Contact dbContact = _dataContext.Contact_Rep.Query(x => x.FK_InnoAppUser == (Guid)this.CurrentUser.ProviderUserKey).FirstOrDefault();
                            if (dbContact != null)
                            {
                                _currentContact = ObjectMapperManager.DefaultInstance.GetMapper<Contact, ManagedContact_MetaModel>().Map(dbContact);
                                _currentContact.FavoriteLanguage = new INNOVACALL.Framework.Common.Models.ViewModels.MetaModels.Language_MetaModel(dbContact.Language.Description);
                            }
                        }
                    }
                }
                return _currentContact;
            }
            protected set
            {
                _currentContact = value;
            }
        }

        /// <summary>
        /// Initializes the view.
        /// </summary>
        /// <param name="pageTitle">The page title.</param>
        /// <param name="openingMessage">The opening message.</param>
        /// <param name="specificCssCollection">The specific CSS collection.</param>
        /// <param name="specificJSCollection">The specific js collection.</param>
        /// <param name="dynamicJSCollection">The dynamic js collection.</param>
        /// <param name="specificJqueryJSCollection">The specific jquery js collection.</param>
        /// <param name="jsVariables">The js variables.</param>
        /// <param name="externalJs">The external js.</param>
        /// <param name="externalCss">The external CSS.</param>
        /// <param name="metaToAdd">The meta to add.</param>
        /// <param name="_dataContext">The _data context.</param>
        /// <param name="displayMenus">if set to <c>true</c> [display menus].</param>
        /// <param name="language">The language.</param>
        /// <param name="adminMode">if set to <c>true</c> [admin mode].</param>
        /// <param name="usesKendoUI">if set to <c>true</c> [uses kendo UI].</param>
        /// <param name="jQueryUITheme">The j query UI theme.</param>
        /// <param name="kendoUITheme">The kendo UI theme.</param>
        /// <param name="currentUser">The current user.</param>
        protected void InitView(
            string pageTitle,
            string openingMessage,
            string[] specificCssCollection,
            string[] specificJSCollection,
            string[] dynamicJSCollection,
            string[] specificJqueryJSCollection,
            string[] jsVariables,
            string[] externalJs,
            string[] externalCss,
            Dictionary<enMeta, string> metaToAdd,
            DataRepositories _dataContext,
            bool displayMenus,
            string language,
            bool adminMode,
            bool usesKendoUI,
            string jQueryUITheme,
            string kendoUITheme,
            MembershipUser currentUser
        )
        {
            //if (currentUser != null)
            //{
            //    Contact dbContact = _dataContext.Contact_Rep.Query(x => x.FK_InnoAppUser == (Guid)currentUser.ProviderUserKey).FirstOrDefault();
            //    CurrentContact = ObjectMapperManager.DefaultInstance.GetMapper<Contact, ManagedContact_MetaModel>().Map(dbContact);
            //    CurrentContact.FavoriteLanguage = new INNOVACALL.Framework.Common.Models.ViewModels.MetaModels.Language_MetaModel(dbContact.Language.Description);
            //}
            //else
            //{
            //    CurrentContact = null;
            //}
            //Initalize view in common layer
            base.InitView_Common(
            pageTitle,
            openingMessage,
            specificCssCollection,
            specificJSCollection,
            dynamicJSCollection,
            specificJqueryJSCollection,
            jsVariables,
            externalJs,
            externalCss,
            metaToAdd,
            _dataContext,
            displayMenus,
            language,
            adminMode,
            usesKendoUI,
            jQueryUITheme,
            kendoUITheme,
            currentUser
            );
            ContentData._enCurrentSiteLayout = PortalEnvironment.SiteLayout;
        }
    }
}